/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.manage.video;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.core.util.KeyValueHelper;
import shop.core.Services;
import shop.core.util.MD5;
import shop.services.manage.video.VideoService;
import shop.services.manage.video.bean.Video;
import shop.core.BaseController;
import shop.core.RequestHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**   
 * @类名称：VideoAction      
 * @创建人：wzl
 * @创建时间：2018-04-23 下午19:30:39      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/manage/video/")
public class VideoAction extends BaseController<Video> {
    private static final Logger logger = LoggerFactory.getLogger(VideoAction.class);
    @Autowired
    private VideoService videoService;
    private static final String page_toList = "/manage/video/videoList";
    private static final String page_toVideoManage = "/manage/video/videoManage";
    private static final String page_toVideoControll= "/manage/video/videoControll";
    private static final String page_toVideoHistory= "/manage/video/videoHistory";

    public VideoService getService() {
        return videoService;
    }

    private VideoAction(){
        super.page_toList = page_toList;
        super.page_toEdit = null;
    }

    /**
     * 跳转到视频管理页面
     *
     * @return
     */
    @RequestMapping("toVideoManage")
    public String toVideoManage() {
        return page_toVideoManage;
    }

    /**
     * 跳转到视频控制页面
     * @return
     */
    @RequestMapping("toVideoControll")
    public String toVideoControll(@ModelAttribute("e") Video e,ModelMap model) {
        e=videoService.selectById(e.getId());
        model.addAttribute("e", e);
        return page_toVideoControll;
    }
    /**
     * 跳转到视频历史页面
     * @return
     */
    @RequestMapping("toVideoHistory")
    public String toVideoHistory(@ModelAttribute("e") Video e,ModelMap model) {
        e=videoService.selectById(e.getId());
        model.addAttribute("e", e);
        return page_toVideoHistory;
    }

    /**
     * 分页查询视频信息
     *
     * @param request 请求
     * @param video    对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectVideoManagePage")
    @ResponseBody
    public PagerModel selectVideoManagePage(HttpServletRequest request, Video video) {
        int offset = 0;
        int pageSize = 10;
        int start = Integer.parseInt(request.getParameter("start"));
        int length = Integer.parseInt(request.getParameter("length"));
        if (start > 0)
            offset = start;
        if (length > 0)
            pageSize = length;
        video.setOffset(offset);
        video.setPageSize(pageSize);
        PagerModel pager = videoService.selectVideoManagePage(video);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }
}
